/*
 * Copyright (c) 2010 Virtium Technology,
 * All Rights Reserved.
 * This work contains trade secrets and confidential material of
 * Virtium Technology.
 *
 * Warning: Any unauthorised dissemination, disclosure or use of the content
 * in whole or in part without the explicit consent of Virtium technology
 * will be deemed as intellectual property infindgement and the
 * offender will be subjected to legal actions.
 *
 * Project  : VPC
 * Name   : StringUtil.java
 *
 */
package com.virtium.vpc.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.log4j.Logger;

/**
 * Provides String utility methods that can be used to perform common
 * operations.
 * 
 * @author TuanAnh
 * 
 */
public class StringUtil {

	private static Logger log = Logger.getLogger(StringUtil.class);

	/**
	 * 
	 */
	public StringUtil() {
	}

	/**
	 * Returns false if the string value is not null or empty, true otherwise.
	 * 
	 * @param fieldValue
	 *            value to be validated
	 * @return
	 */
	public static boolean isEmpty(String fieldValue) {

		if ((fieldValue == null) || (fieldValue == "")
				|| (fieldValue.equalsIgnoreCase(""))) {
			return true;
		}

		return false;
	}

	/**
	 * Converts normal Array of <code>String</code> into <code>List</code>.
	 * 
	 * @param arrStr
	 *            Array of String to be converted
	 * @return a List
	 */
	public static List toList(String[] arrStr) {

		List ret = null;
		try {
			if (arrStr != null) {
				ret = Arrays.asList(arrStr);
			}
		} catch (Exception e) {
			log.debug("Exception toList", e);
		} finally {
			return ret;
		}
	}

	/**
	 * This method returns a Collection of String objects without the
	 * delimiters.
	 * 
	 * @param theString
	 *            The string to be formatted
	 * @param delim
	 *            The delimiter
	 * @return Collection
	 */
	public static Collection<String> removeDelimiter(String theString,
			String delim) {
		Collection<String> stringCol = new ArrayList<String>();
		StringTokenizer st = new StringTokenizer(theString, delim);
		while (st.hasMoreTokens()) {
			stringCol.add(st.nextToken().trim());
		}
		return stringCol;
	}
}
